package com.mxpio.erp.plm.controller;

import com.mxpio.erp.common.plm.entity.ProjectTaskDeliverable;
import com.mxpio.erp.common.plm.entity.ProjectTaskMembersTime;
import com.mxpio.erp.common.plm.service.ProjectTaskMembersTimeService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.List;

@Tag(name = "ProjectTaskMembersTimeController", description = "项目-任务-成员工时统计")
@RestController
@RequestMapping("/erp/plm/pro/task/mem/time/")
public class ProjectTaskMembersTimeController {

    @Autowired
    private ProjectTaskMembersTimeService projectTaskMembersTimeService;

    @GetMapping("list")
    @Operation(summary = "成员工时统计列表", description = "成员工时统计列表（无分页）", method = "GET")
    public Result<List<ProjectTaskMembersTime>> list(@Parameter(description="查询参数") Criteria criteria) throws UnsupportedEncodingException {
        List<ProjectTaskMembersTime> list = projectTaskMembersTimeService.list(ProjectTaskMembersTime.class, criteria);
        return Result.OK(list);
    }

    @GetMapping("page")
    @Operation(summary = "成员工时统计列表", description = "成员工时统计列表（分页）", method = "GET")
    public Result<Page<ProjectTaskMembersTime>> page(@Parameter(description="查询参数") Criteria criteria, @Parameter(description="每页条数")Integer pageSize, @Parameter(description="页号")Integer pageNo) throws UnsupportedEncodingException {
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<ProjectTaskMembersTime> pageResult = projectTaskMembersTimeService.listPage(ProjectTaskMembersTime.class, page, criteria);
        return Result.OK(pageResult);
    }

    @GetMapping("list/{taskCode}")
    @Operation(summary = "根据任务编码获取成员工时统计列表", description = "根据任务编码获取成员工时统计列表（无分页）", method = "GET")
    public Result<List<ProjectTaskMembersTime>> listByTaskCode(@PathVariable(name = "taskCode", required = true) String taskCode) {
        Criteria criteria = Criteria.create().addCriterion("taskCode", Operator.EQ, taskCode);
        List<ProjectTaskMembersTime> list = projectTaskMembersTimeService.list(ProjectTaskMembersTime.class, criteria);
        return Result.OK(list);
    }

    @GetMapping("list/all/{proCode}")
    @Operation(summary = "根据项目编码获取成员工时统计列表", description = "根据项目编码获取成员工时统计列表（无分页）", method = "GET")
    public Result<List<ProjectTaskMembersTime>> listByProcode(@PathVariable(name = "proCode", required = true) String proCode) {
        Criteria criteria = Criteria.create().addCriterion("proCode", Operator.EQ, proCode);
        List<ProjectTaskMembersTime> list = projectTaskMembersTimeService.list(ProjectTaskMembersTime.class, criteria);
        return Result.OK(list);
    }


}
